import { createRouter, createWebHistory, RouteRecordRaw } from 'vue-router'

const routes: Array<RouteRecordRaw> = [
  {
    path: '/',
    name: 'login',
    component: () => import(/* webpackChunkName: "about" */ '../views/Login.vue'),
  },
  {
    path: '/manager/view',
    name: 'managerView',
    component: () => import(/* webpackChunkName: "about" */ '../views/manager/ManagerView.vue'),
    beforeEnter: (to, from, next) => {
      if (from.name == 'login') {
        next()
      } else {
        next(false)
      }
    },
    children: [
      {
        path: 'task',
        name: 'managerTask',
        meta: {
          type: "manager",
          isShow: true,
          title: "管理报修订单",
          icon: "Tickets",
        },
        component: () => import(/* webpackChunkName: "about" */ '../views/manager/ManagerTask.vue'),
      },
      {
        path: 'info',
        name: 'managerInfo',
        meta: {
          type: "manager",
          isShow: true,
          title: "个人信息",
          icon: "setting",
        },
        component: () => import(/* webpackChunkName: "about" */ '../views/manager/ManagerInfo.vue'),
      }
    ]
  },
  {
    path: '/user/view',
    name: 'userView',
    component: () => import(/* webpackChunkName: "about" */ '../views/user/UserView.vue'),
    beforeEnter: (to, from, next) => {
      if (from.name == 'login') {
        next()
      } else {
        next(false)
      }
    },
    children: [
      {
        path: 'task',
        name: 'userTask',
        meta: {
          type: "user",
          isShow: true,
          title: "我的报修订单",
          icon: "Tickets",
        },
        component: () => import(/* webpackChunkName: "about" */ '../views/user/UserTask.vue'),
      },
      {
        path: 'info',
        name: 'userInfo',
        meta: {
          type: "user",
          isShow: true,
          title: "个人信息",
          icon: "setting",
        },
        component: () => import(/* webpackChunkName: "about" */ '../views/user/UserInfo.vue'),
      }
    ]
  },
  {
    path: '/worker/view',
    name: 'workerView',
    component: () => import(/* webpackChunkName: "about" */ '../views/worker/WorkerView.vue'),
    beforeEnter: (to, from, next) => {
      if (from.name == 'login') {
        next()
      } else {
        next(false)
      }
    },
    children: [
      {
        path: 'task',
        name: 'workerTask',
        meta: {
          type: "worker",
          isShow: true,
          title: "我的报修订单",
          icon: "Tickets",
        },
        component: () => import(/* webpackChunkName: "about" */ '../views/worker/WorkerTask.vue'),
      },
      {
        path: 'info',
        name: 'workerInfo',
        meta: {
          type: "worker",
          isShow: true,
          title: "个人信息",
          icon: "setting",
        },
        component: () => import(/* webpackChunkName: "about" */ '../views/worker/WorkerInfo.vue'),
      }
    ]
  }

]

const router = createRouter({
  history: createWebHistory(process.env.BASE_URL),
  routes
});

export default router
